<template>
  <div>
    <el-breadcrumb separator="/">
      <el-breadcrumb-item :to="{ path: '/' }">
        <i class="el-icon-caret-right"></i> 个人中心</el-breadcrumb-item>
      <el-breadcrumb-item>收货地址</el-breadcrumb-item>
    </el-breadcrumb>

    <el-divider></el-divider>
    <el-button style="float: right" type="warning" round @click="addAddress()">添加收获地址</el-button>

    <el-table :data="tableData" border style="width: 100%">
      <el-table-column prop="name" label="收货人" width="120" align="center"></el-table-column>
      <el-table-column prop="provincial" label="省份" width="120" align="center"></el-table-column>
      <el-table-column prop="detailed" label="详细地址" width="279" align="center"></el-table-column>
      <el-table-column prop="phone" label="手机号码" width="200" align="center"></el-table-column>
      <el-table-column label="操作" width="120" align="center">
        <template slot-scope="scope">
<!--          <el-button type="primary" icon="el-icon-edit" circle size="mini"
                     @click="handleEdit(scope.row)"></el-button>-->
          <el-button type="danger" icon="el-icon-delete"circle size="mini"
                     @click="openDeleteConfirm(scope.row)"></el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
import axios from "axios";

export default {
  data() {
    return {
      tableData: []
      }
  },
  methods: {
    addAddress(){
      this.$router.push("/information/AddressAdd")
    },
    /*handleEdit(address){
      location.href="/information/AddressUpdate?id="+address.id;
      /!*this.$router.push("/information/AddressUpdate?id=address.id")*!/
    },*/
    handleDelete(address){
      console.log("准备删除"+address.id)
      let url='http://localhost:8080/address/delete/'+address.id;
      this.axios.post(url).then((response)=>{
        let responseBody=response.data;
        if(responseBody.state==20000){
          this.loadCommentsList();
          this.$message({
            type: 'success',
            message: '删除成功'
          });
          this.loadAddresssList();
        }else {
          this.$message({
            type: 'info',
            message: responseBody.message
          });
          this.loadAddresssList();
        }
      })
    },
    openDeleteConfirm(address){
      let message = '此操作将永久删除【'+address.name+'】,是否继续';
      this.$confirm(message, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.handleDelete(address);
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '删除取消'
        });
      });
    },
    loadAddresssList(){
      let url = "http://localhost:8080/address/list";
      axios.get(url).then((response)=>{
        this.tableData=response.data.data;
      })
    }
  },
  mounted() {
    this.loadAddresssList();
  }
}
</script>

<style scoped>

</style>